<template>
	<view class="recharge">
		<text>选择充值金额</text>
		<view class="cards">
			<view class="card"
				:style="(item.money==recharge)?'border: 4rpx solid #e89abe;box-shadow: 0rpx 5rpx 20rpx #ca86a7;':''"
				v-for="item in money" @click="change(item.money)">
				<uni-icons v-show="item.money==recharge" type="checkmarkempty" color="#e89abe"></uni-icons>
				<text :style="(item.money==recharge)?'color:#e89abe;':''">￥{{item.money}}</text>
			</view>
		</view>
		<view class="money">
			<text>充值金额:￥{{recharge}}</text>
		</view>
		<view class="btn" @click="userRecharge()">
			<text>确认充值</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				money: [{
					money: 100
				}, {
					money: 200
				}, {
					money: 300
				}, {
					money: 500
				}, {
					money: 1000
				}, ],
				recharge: 100,
			}
		},
		onLoad() {
			this.userId = JSON.parse(window.localStorage.getItem("user"));
		},
		methods: {
			change(money) {
				this.recharge = money
			},
			userRecharge(){
				uni.request({
					url:"/user/recharge",
					method:"GET",
					data:{
						userId:this.userId,
						money:this.recharge
					},
					success: (res) => {
						if (res.data.code==200) {
							uni.showToast({
								title:res.data.data,
								icon:'success'
							})
						} else{
							uni.showToast({
								title:"失败",
								icon:'error'
							})
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.recharge {
		text-align: center;
	}

	.money,
	.btn {
		font-size: 40rpx;
		font-weight: 600;
	}

	.money {
		margin-top: 100rpx;
	}

	.btn {
		width: 70%;
		height: 100rpx;
		margin: 20rpx auto;
		background: linear-gradient(90deg, #f6cce8, #e89abe);
		box-shadow: 0rpx 5rpx 20rpx #e89abe;
		display: flex;
		justify-content: center;
		align-items: center;
		color: white;
		border-radius: 50rpx;
	}

	.cards {
		display: flex;
		flex-flow: row wrap;

		.card {
			height: 250rpx;
			border: 4rpx solid rgba(0, 0, 0, 0);
			border-radius: 20rpx;
			box-shadow: 0rpx 5rpx 20rpx #aaaaaa;
			width: 45%;
			margin: 20rpx 2.5%;
			display: flex;
			justify-content: center;
			align-items: center;
			box-sizing: border-box;

			text {
				width: 100;
				font-size: 50rpx;
				font-weight: 600;
			}

		}
	}
</style>